/**
 * Config module for Lab layout
 */
import objectPath from "object-path"
import merge from "deepmerge"
import defaultCfg from "@/core/DefaultLayoutConfig"
import {Mutations} from "./Enums"

const LabConfigModule = {
    state: {
        config: defaultCfg,
        initial: defaultCfg,
        menu: {}
    },
    mutations: {
        [Mutations.SET_LAYOUT_CONFIG]: (state, payload) => state.config = payload,
        [Mutations.SET_MENU_CONFIG]: (state, payload) => state.menu = payload,
        [Mutations.RESET_LAYOUT_CONFIG]: (state) => state.config = Object.assign({}, state.initial),
        [Mutations.OVERRIDE_LAYOUT_CONFIG]: (state) => {
            state.config = state.initial = Object.assign(
                {},
                state.initial,
                JSON.parse(window.localStorage.getItem("config") || "{}")
            );
        },
        [Mutations.OVERRIDE_PAGE_LAYOUT_CONFIG]: (state, payload) => state.config = merge(state.config, payload)
    },
    getters: {
        config: (state) => (path, defaultValue) => objectPath.get(state.config, path, defaultValue),
        menu: (state) => state.menu
    }

}
export default LabConfigModule